package com.b2.controller.wx;

import com.b2.pojo.entity.Director;
import com.b2.pojo.entity.Parent;
import com.b2.result.Result;
import com.b2.service.DirectorService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wx/Kindergardern")
@Slf4j
@Api(tags = "微信幼儿园相关接口")
@CrossOrigin
public class KindergardenController {



       @Autowired
       DirectorService directorService;

       //得到幼儿园名字，用于家长和幼儿园老师填写幼儿园
       @GetMapping("getname")
       @ApiOperation(value = "得到幼儿园名字，用于家长和幼儿园老师填写幼儿园")
       public Result<List<Director>> getname(){
      List<Director> lists= directorService.getname();
      return Result.success(lists);
       }

    /**
     * 根据手机号查询家长姓名
     * @param phone
     * @return
     */
    @ApiOperation("根据手机号查询园长姓名")
    @PostMapping("/selectNameByPhone")
    public Result<String> selectName(String phone){
        if (phone == null){
            return Result.error("手机号不能为空");
        }
        Director director = directorService.getOne(Wrappers.<Director>lambdaQuery().eq(Director::getPhone, phone));
        return Result.success(director.getName());
    }

}
